package hyrpt

class WipInventoryController {
    def dynamicQueryService

    def wipInventory() {
        def pageCurrent = params.pageCurrent ? Integer.parseInt(params.pageCurrent) : 1
        def pageSize = params.pageSize ? Integer.parseInt(params.pageSize) : 10
        params.startno = (pageSize * (pageCurrent - 1)) + 1
        params.endno = pageSize * pageCurrent
        def tableHeadList = []
        def wipInventory = []
        def pageSizeList = [10, 20, 50, 100]
        def totalCount = 0
        def wipInventorySumQty = [];
        if (params.EXPORT_CONTENT_NAME == 'Excel') {
            params.SYS_QUERY_NAME = 'wipInventory'
            wipInventory = dynamicQueryService.queryForList(params)
            if (wipInventory.size() > 0) {
                tableHeadList = wipInventory[0].keySet()
            }
            params.SYS_QUERY_NAME = 'wipInventoryCount'
            totalCount = dynamicQueryService.queryForList(params)[0].TOTALCOUNT

            params.SYS_QUERY_NAME = 'wipInventorySumQty'
            wipInventorySumQty = dynamicQueryService.queryForList(params)
        }
        print(tableHeadList)
        [startno                   : params.startno ?: '',
         endno                     : params.endno ?: '',
         pageSize                  : pageSize,
         totalCount                : totalCount,
         pageSizeList              : pageSizeList,
         tableHeadList             : tableHeadList,
         wipInventory              : wipInventory,
         wipInventorySumQty        : wipInventorySumQty,
         lotId                     : params.lotId ?: '',
         startTime                 : params.startTime ?: '',
         endTime                   : params.endTime ?: '',
         lineId                    : params.lineId ?: '',
         partName                  : params.partName ?: '',
         partDesc                  : params.partDesc ?: '',
         docStatus                 : params.docStatus ?: '',
         stepName                  : params.stepName ?: ''
        ]
    }
}
